#!/usr/bin/python
#application.py


#TODO:
#if the last tab has some search text, deleting it (v)
#there should always be a tab (v)
#deletion of tab to call changing of the tab(v)

#add an html button shortcut to clearing the lineEdit
#shortcuts for add and remove tab and for navigating through tabs
#support advanced search into full texts
#support search within current text with a shortcut
#write a doc file
#fix the html layout a bit
#maybe add a close button to the tabs
#support logical operations

import sys
import welcome
from generatehtml import *
from slots import *
from PyQt4.QtCore import Qt, SIGNAL
from PyQt4.QtGui import *
from PyQt4.QtSql import *
from ui_mainwin import *
from sqlImporter import *
from generatehtml import *
import os

class Application(QtGui.QApplication):
	'''a basic interaction class'''
	def __init__(self):
		QtGui.QApplication.__init__(self, sys.argv)
		
		self.htmlGenerators=htmlGen(self)
		
		#setup Sql here
		self.database=self.setupSql()
		
		#
		self.table=sqlImporter(self.database)
		self.table.select()
		
		window = QtGui.QMainWindow()
		self.ui = Ui_MainWindow()
		self.ui.setupUi(window)
		self.slot=slots(self,self.ui,window)
		self.htmlGenerators.generateHtmlSource(range(3))
		window.show()
		
		self.slot.newTab()
		self.ui.curBrow().setHtml(welcome.welcome_message)
		
		sys.exit(self.exec_())
	
	def setupSql(self,name="databases/default.db"):
		'''sets up the default database connection'''
		database=QSqlDatabase.addDatabase("QSQLITE")
		database.setDatabaseName(name)
		if not database.open():
			print "Error opening SQLite database"
		return database
	
	def showCurrentDB(self):
		'''show all the contents of the current table on a separate window(debuging purposes)'''
		self.debuger=QTableView()
		self.debuger.setWindowTitle("The selected items of the current table")
		self.debuger.setModel(self.table)
		self.debuger.show() 


app=Application()
